<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="/css/elementUI.css">
    <script src="/js/vue.js"></script>
    <script src="/js/elementUI.js"></script>
    <script src="/js/axios.js"></script>
</head>
<body>

<div id="app">
    账号：<el-input v-model="user.username" placeholder="请输入用户名" style="width: 200px;" clearable></el-input>
    <br>
    密码：<el-input v-model="user.password" show-password placeholder="请输入密码" style="width: 200px;" clearable></el-input>
    <br>


    <el-button type="primary" @click="toLogin">登录</el-button>


</div>
<script>
    new Vue({
        el:"#app",
        data:{
            user:{
                username:"",
                password:""
            }

        },
        watch:{
        },
        methods:{
            toLogin(){
                axios.post("/user/login",this.user).then(res=>{
                    let myresult = res.data;//MyResult
                    if(myresult.code==0){
                        let user = myresult.data;
                        //跳转页面
                        //放入缓存
                        localStorage.setItem("user_shenpi_07",JSON.stringify(user));

                        if(user.role=="HR"){
                            location.href = "/copy.html";
                        }else if(user.role=="普通员工"){
                            location.href = "/apply.html";
                        }else if(user.role=="领导"){
                            location.href = "/shenpi.html";
                        }

                    }else{
                        this.$message.error(myresult.msg)
                    }



                })
            },
            initData(){

            }

        },
        created(){
            this.initData()
        }
    })
</script>

</body>
</html>
